package cn.jbit.supermarker.service.impl;

import java.util.List;

import cn.jbit.supermarker.dao.UserDao;
import cn.jbit.supermarker.dao.impl.UserDaoImpl;
import cn.jbit.supermarker.entity.User;
import cn.jbit.supermarker.service.UserService;
import cn.jbit.supermarker.util.Page;

import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.regexp.internal.recompile;


public class UserServiceImpl implements UserService {
	
	private UserDao userDao=new UserDaoImpl();
	
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	
	public List<User> getUserList() {
		// TODO Auto-generated method stub
		return userDao.getUserList();
	}

	
	public boolean addUser(User user) {
		// TODO Auto-generated method stub
		return userDao.addUser(user);
	}

	
	public boolean updateUser(User user) {
		// TODO Auto-generated method stub
		return userDao.updateUser(user);
	}

	
	public boolean deleteUser(int id) {
		// TODO Auto-generated method stub
		return userDao.deleteUser(id);
	}

	
	public User getUserById(int id) {
		// TODO Auto-generated method stub
		return userDao.getUserById(id);
	}

	
	public int getTotalCount(String userName) {
		// TODO Auto-generated method stub
		return userDao.getTotalCount(userName);
	}

	
	public List<User> getUserPageList(int pageNo, int pageSize,String userName) {
		// TODO Auto-generated method stub
		return userDao.getUserPageList(pageNo, pageSize,userName);
	}

	public User login(String loginName,String loginPwd){
		return userDao.login(loginName,loginPwd);
	}
	public static void main(String[] args) {
		UserServiceImpl userServiceImpl=new UserServiceImpl();
		User user =new User();
		Page page=new Page();
		//添加
//		user.setName("张三");
//		user.setAddree("北京市海淀区");
//		user.setGender(1);
//		user.setLoginnane("admin");
//		user.setLoginpwd("123");
//		user.setPhone("1234404");
//		user.setUser_type(0);
//		boolean flag=userServiceImpl.addUser(user);
		//修改
//		 user.setUser_id(5);
//		 user.setName("刘能");
//		 user.setLoginnane("liuneng");
//		 user.setLoginpwd("456");
//		 user.setAddree("beijignshi");
//		 user.setBirthdate("1900-12-23");
//		 user.setGender(0);
//		 user.setPhone("1823949499");
//		 user.setUser_type(2);
//		boolean flag= userServiceImpl.updateUser(user);
		//删除
//		user.setUser_id(4);
//		boolean flag=userServiceImpl.deleteUser(user);
		 
//		List<User> userList=userServiceImpl.getUserList();
//		for (User user2 : userList) {
//			System.out.println(user2.getName()+"\t"+user2.getLoginnane()+"\t"+user2.getLoginpwd());
//		}
//	if(flag){
//		System.out.println("成功");
//	}else{
//		System.out.println("失败");
//	}
//	List<User> userList=userServiceImpl.getUserPageList(0, 5, "兰");	
//		for (User user2 : userList) {
//		System.out.println(user2.getName()+user2.getUser_id());
//		}
		
		User user2=userServiceImpl.searchLogName("landeqing");
		if(user2!=null){
			System.out.println("存在");
		}else{
			System.out.println("不存在");
		}
	}

	@Override
	public User searchLogName(String userName) {
		// TODO Auto-generated method stub
		return userDao.searchLogName(userName);
	}
	
	
	
	
}
